<?php
//
/*abstract class Tile{
    abstract function getWealthFactor();
}

class Plains extends Tile{
    private $wealthFactor = 2;
    public function getWealthFactor()
    {
        return $this->wealthFactor;
    }
}

abstract class TileDecorator extends Tile{
    protected $tile;
    public function __construct(Tile $tile)
    {
        $this->tile = $tile;
    }
}

class DiamondDecorator extends TileDecorator{
    public function getWealthFactor()
    {
        return ($this->tile->getWealthFactor() + 2);
    }
}

class PollutionDecorator extends TileDecorator{
    public function getWealthFactor()
    {
        return $this->tile->getWealthFactor() - 4;
    }
}

$tile = new Plains();
echo $tile->getWealthFactor();

$tile = new DiamondDecorator($tile);
echo $tile->getWealthFactor();

//有砖石又受到污染的地
$tile = new PollutionDecorator(new DiamondDecorator(new Plains()));
print $tile->getWealthFactor();*/

//实际的装饰器例子
class RequestHelper{}

abstract class ProcessRequest{
    abstract function process(RequestHelper $req);
}

class MainProcess extends  ProcessRequest{
    function process(RequestHelper $req)
    {
        print __CLASS__.':处理有用的请求';
    }
}

abstract class DecorateProcess extends ProcessRequest{
    protected $processRequest;

    function __construct(ProcessRequest $pr)
    {
        $this->processRequest = $pr;
    }
}

class LogRequest extends DecorateProcess{
    public function process(RequestHelper $req)
    {
        print __CLASS__.':日志处理';
        $this->processRequest->process($req);
    }
}

class AuthenticateRequest extends DecorateProcess{
    public function process(RequestHelper $req)
    {
        print __CLASS__.':授权处理';
        $this->processRequest->process($req);
    }
}


class SturctureRequest extends DecorateProcess{
    public function process(RequestHelper $req)
    {
        print __CLASS__.':处理请求数据';
        $this->processRequest->process($req);
    }
}

$process = new AuthenticateRequest(new SturctureRequest(new LogRequest(new MainProcess())));
$process->process(new RequestHelper());